/*  GStruct: data structure helpers for Java
 *  Copyright (C) 2011 Giulio Franco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package gstruct.extensions;

/**
 * Predicate that applies to objects that can be cast to a given type
 * @author Giulio Franco <giulio_franco@msn.com>
 *
 * @param <E>	Type the objects should be castable to
 */
public class CastPredicate<E> implements Predicate<Object> {

	private final Class<E> cls;
	
	/**
	 * Creates a CastPredicate
	 * @param cls	class the object should be cast to
	 */
	public CastPredicate(Class<E> cls) {
		this.cls = cls;
	}
	
	@Override
	public boolean appliesTo(Object obj) {
		return cls.isInstance(obj);
	}
	
}
